<?php

namespace Product\Model;

use Zend\Db\TableGateway\TableGateway;
use Product\Entity\Product;

class ProductTable
{
    protected $tableGateway;
    
    public function __construct(TableGateway $tableGateway) {
        $this->tableGateway = $tableGateway;
    }
    
    public function saveProduct(Product $product)
    {
        $data = array(
            'name' => $product->getName(),
            'price' => $product->getPrice() ,
        );
        
        $id = (int)$product->getId();
        if($id == 0)
        {
           
            $this->tableGateway->insert($data);
        }      
	return $this->tableGateway->getLastInsertValue();  
    }
}
